﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
                    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
                    xmlns:local="clr-namespace:Tequila.Phone.Controls">

    <Style TargetType="local:FlowDocumentElement">
        <Setter Property="IsReadOnly" Value="True"/>
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="BorderBrush" Value="Transparent" />
        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="HorizontalAlignment" Value="Stretch" />
        <Setter Property="VerticalAlignment" Value="Stretch" />
        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        <Setter Property="VerticalContentAlignment" Value="Stretch" />
        <Setter Property="Padding" Value="0" />
        <Setter Property="Margin" Value="0" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="local:FlowDocumentElement">
                    <Border Background="{TemplateBinding Background}" 
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}" 
                            Margin="{TemplateBinding Margin}"
                            Padding="{TemplateBinding Padding}">
                        <ContentControl x:Name="ContentElement"
                                        HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" 
                                        VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
    <Style TargetType="local:FlowDocument">
        <Setter Property="VerticalContentAlignment" Value="Stretch" />
        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        <Setter Property="VerticalAlignment" Value="Stretch" />
        <Setter Property="HorizontalAlignment" Value="Stretch" />
        <Setter Property="ParagraphOffset" Value="0,0,0,12"/>
        <Setter Property="ContentPadding" Value="0"/>
        <Setter Property="Padding" Value="0"/>
        <Setter Property="ContentMargin" Value="0,0,6,0"/>
        <Setter Property="Margin" Value="0,0,2,0"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="local:FlowDocument">
                    <ScrollViewer x:Name="ScrollViewer" 
                                  HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
                                  VerticalAlignment="{TemplateBinding VerticalAlignment}"
                                  Padding="{TemplateBinding Padding}"
                                  Margin="{TemplateBinding Margin}"
                                  ScrollViewer.VerticalScrollBarVisibility="Auto">
                        <ItemsControl x:Name="Container" 
                                      VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
                                      HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                      Padding="{TemplateBinding ContentPadding}"
                                      Margin="{TemplateBinding ContentMargin}">
                        </ItemsControl>
                    </ScrollViewer>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="local:InfiniteListBox">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="local:InfiniteListBox">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <ScrollViewer x:Name="ScrollViewer"
                                      Grid.Row="0"
                                      VerticalScrollBarVisibility="Auto"
                                      HorizontalScrollBarVisibility="Disabled"
                                      BorderBrush="{TemplateBinding BorderBrush}" 
                                      BorderThickness="{TemplateBinding BorderThickness}" 
                                      Background="{TemplateBinding Background}" 
                                      Foreground="{TemplateBinding Foreground}" 
                                      Padding="{TemplateBinding Padding}">
                            <ItemsPresenter/>
                        </ScrollViewer>
                        <toolkit:PerformanceProgressBar x:Name="loadingIndicator"
                                                        Grid.Row="1"
                                                        Visibility="Visible"
                                                        IsIndeterminate="false"
                                                        Margin="0,0,0,10"
                                                        Foreground="{TemplateBinding ProgressForeground}"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="local:ImageButton">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="local:ImageButton">
                    <Grid>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal" />
                                <VisualState x:Name="Disabled">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" 
                                                                       Duration="00:00:00.0010000"
                                                                       Storyboard.TargetName="ButtonImage" 
                                                                       Storyboard.TargetProperty="UriSource">
                                            <DiscreteObjectKeyFrame KeyTime="0"
                                                                    Value="{Binding DisabledImageSource, RelativeSource={RelativeSource TemplatedParent}}">
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Pressed">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ButtonImage" 
                                                                       Storyboard.TargetProperty="(UIElement.Opacity)">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="0.0">
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ButtonImageClicked" 
                                                                       Storyboard.TargetProperty="(UIElement.Opacity)">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="1.0">
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Image x:Name="ButtonImage"
                               Height="{TemplateBinding Height}" 
                               Width="{TemplateBinding Width}"
                               Opacity="1.0"
                               Source="{TemplateBinding EnabledImageSource}">
                        </Image>
                        <Image x:Name="ButtonImageClicked"
                               Height="{TemplateBinding Height}" 
                               Width="{TemplateBinding Width}"
                               Opacity="0.0"
                               Source="{TemplateBinding ClickedImageSource}">
                        </Image>
                        <ContentPresenter Content="{TemplateBinding Content}"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>